<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //有这个需求:回家给女朋友做饭

        // 1.去菜市场买菜
        // 2.回家洗菜
        // 3.开始做饭
        // 4.做饭完成开始吃饭
        // 5.吃完饭洗碗

        var flag = 1;

        function stepl(resolve, reject) {
            console.log("准备去买菜");
            if (flag) {
                resolve("我女朋友不挑食,什么都吃,很快就完成了买菜,嘿嘿")
            } else {
                reject("街上没有女朋友喜欢的菜,正在做思想工作,正在沟通")
            }
        }

        function step2(resolve, reject) {
            console.log("准备洗菜");
            if (flag) {
                resolve("洗菜比较顺利,因为有手套洗菜");
            } else {
                reject("家里没有水费,没法正常洗菜,搓衣板已经准备好了");
                flag = 0
            }
        }

        function step3(resolve, reject) {
            console.log("准备开始做饭");
            flag = 0;
            if (flag == 1) {
                resolve("做饭已经完成");
            } else {
                reject("家里没有煤气,这次自觉去搓衣板上")
            }
        }

        function step4(resolve, reject) {
            console.log("准备开始做饭");
            if (flag == 1) {
                resolve("做饭已经完成");
            } else {
                reject("家里没有煤气,这次自觉去搓衣板上")
            }
        }
        new Promise(stepl).then(function(val1) {
            console.log(val1);
            return new Promise(step2);
        }).then(function(val2) {
            console.log(val2);
            return new Promise(step3);
        }).then(function(val3) {
            console.log(val3);
            return new Promise(step4)
        }).then(function(val4) {
            console.log(val4);
        })
    </script>
</body>

</html>